{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "651de65b-8403-44bb-a194-bfdd9018d760",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "#from vk_download import main\n",
    "#import scipy.sparse as sprs\n",
    "import time\n",
    "from tqdm.auto import tqdm\n",
    "import os\n",
    "import random\n",
    "import datetime\n",
    "#from threading import Thread\n",
    "#from multiprocessing import Process\n",
    "import numpy as np\n",
    "from scipy.sparse import csr_matrix, lil_matrix, csc_matrix\n",
    "#import scipy.sparse as sprs\n",
    "#from collections import OrderedDict\n",
    "#import shutil\n",
    "import matplotlib.pyplot as plt\n",
    "#import seaborn as sns\n",
    "import networkx as nx\n",
    "from IPython.display import clear_output\n",
    "#from statsmodels.stats.proportion import proportion_confint\n",
    "#import statsmodels.api as sm\n",
    "#from scipy.optimize import minimize\n",
    "import matplotlib as mpl\n",
    "import copy\n",
    "from scipy.stats import mannwhitneyu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a3022713-4e68-4e24-82f7-5593bc159d62",
   "metadata": {},
   "outputs": [],
   "source": [
    "from Support import LoadSeveralExperiments"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb547409-608d-47d8-b7e4-334a5fcce65e",
   "metadata": {},
   "source": [
    "# Define hyperparameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e245d52f-deb1-4296-8f57-3d65e1ed9c57",
   "metadata": {},
   "outputs": [],
   "source": [
    "#------------------------------------ Define constant hyperparameters\n",
    "\n",
    "N = 100  # number of agents\n",
    "T = 1000  # number of iterations (is equal to the number of agents)\n",
    "\n",
    "N_Bots = 0  # number of bots\n",
    "T_bots = 0  # \n",
    "\n",
    "m = 3  # number of opinions \n",
    "\n",
    "OpinionAlphabet = np.arange(m)  # possible opinions in the model (as in the SCARDO model) \n",
    "\n",
    "ActivationProbabilitiesType = 'uniform'\n",
    "\n",
    "\n",
    "OrderOfActions = 'LikeFirst'\n",
    "#OrderOfActions = 'ReplyFirst'\n",
    "\n",
    "LikingProbabilities_Bots = np.array([[1,   0,   0], \n",
    "                                     [0,   0,   0], \n",
    "                                     [0,   0,   1]])\n",
    "\n",
    "\n",
    "ReplyWritingProbabilities_Bots = np.array([[1,  0,   1], \n",
    "                                           [0,  0,   0], \n",
    "                                           [1,  0,   1]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "60b92838-1aad-4ca3-99d1-701b02b2af40",
   "metadata": {},
   "outputs": [],
   "source": [
    "AgentsArgs = ActivationProbabilitiesType, OrderOfActions\n",
    "    \n",
    "BotsArgs = N_Bots, T_bots, ReplyWritingProbabilities_Bots, LikingProbabilities_Bots"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af644873-c493-4043-890e-cc4a6daf4fae",
   "metadata": {},
   "source": [
    "# Distribution 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "603f8635-96df-472c-9c66-b5d81fa6490a",
   "metadata": {},
   "outputs": [],
   "source": [
    "(Scale, Basis_Like, Basis_Reply) = (1/2, 0.15, 0.05)\n",
    "#(Scale, Basis_Like, Basis_Reply) = (3, 0.15, 0.05)\n",
    "#(Scale, Basis_Like, Basis_Reply) = (1/2, 0, 0)\n",
    "#(Scale, Basis_Like, Basis_Reply) = (3, 0, 0)\n",
    "\n",
    "\n",
    "ScaleFactor_Like = Basis_Like / (1 + Basis_Like)  # the total sum if the number of likes tend to infty is equal to 0.15\n",
    "Ratio_Like = ScaleFactor_Like\n",
    "\n",
    "ScaleFactor_Reply = Basis_Reply / (1 + Basis_Reply)  # the total sum if the number of likes tend to infty is equal to 0.025\n",
    "Ratio_Reply = ScaleFactor_Reply\n",
    "\n",
    "#------------------------------------------------------------------------\n",
    "\n",
    "alpha = 0\n",
    "beta = 0\n",
    "gamma = 0\n",
    "delta = 0\n",
    "        \n",
    "omega = 0.5\n",
    "        \n",
    "InitialOpinionDistribution = [0.15, 0.7, 0.15]\n",
    "\n",
    "RankingAlgorithmType = 'Time'\n",
    "#RankingAlgorithmType = 'LikesCount'\n",
    "#ankingAlgorithmType = 'RepliesCount'\n",
    "\n",
    "VariableParameters = RankingAlgorithmType, alpha, beta, gamma, delta, Basis_Like, Basis_Reply, Scale, omega, InitialOpinionDistribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "15bb63b4-97b0-46ce-999a-3884281a99b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "Records = LoadSeveralExperiments(N, T, m, OpinionAlphabet, AgentsArgs, BotsArgs, VariableParameters)\n",
    "\n",
    "ResultsWin = []\n",
    "\n",
    "for i in range(len(Records)):\n",
    "    \n",
    "    ResultsWin.append( [ (Records[i][1][-1] - Records[i][1][0]) ] )\n",
    "    \n",
    "distr1 = np.array(ResultsWin).ravel()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eafd1048-acbe-4eda-a93d-bfee2a2f014e",
   "metadata": {},
   "source": [
    "# Distribution 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "50b5a16d-df0f-4daa-8ff3-f92dbdc73b47",
   "metadata": {},
   "outputs": [],
   "source": [
    "#(Scale, Basis_Like, Basis_Reply) = (1/2, 0.15, 0.05)\n",
    "(Scale, Basis_Like, Basis_Reply) = (3, 0.15, 0.05)\n",
    "#(Scale, Basis_Like, Basis_Reply) = (1/2, 0, 0)\n",
    "#(Scale, Basis_Like, Basis_Reply) = (3, 0, 0)\n",
    "\n",
    "\n",
    "ScaleFactor_Like = Basis_Like / (1 + Basis_Like)  # the total sum if the number of likes tend to infty is equal to 0.15\n",
    "Ratio_Like = ScaleFactor_Like\n",
    "\n",
    "ScaleFactor_Reply = Basis_Reply / (1 + Basis_Reply)  # the total sum if the number of likes tend to infty is equal to 0.025\n",
    "Ratio_Reply = ScaleFactor_Reply\n",
    "\n",
    "#------------------------------------------------------------------------\n",
    "\n",
    "alpha = 0\n",
    "beta = 0\n",
    "gamma = 0\n",
    "delta = 0\n",
    "        \n",
    "omega = 0.5\n",
    "        \n",
    "InitialOpinionDistribution = [0.15, 0.7, 0.15]\n",
    "\n",
    "#RankingAlgorithmType = 'Time'\n",
    "RankingAlgorithmType = 'LikesCount'\n",
    "#RankingAlgorithmType = 'RepliesCount'\n",
    "\n",
    "VariableParameters = RankingAlgorithmType, alpha, beta, gamma, delta, Basis_Like, Basis_Reply, Scale, omega, InitialOpinionDistribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "120b7a8b-0a77-4641-b2c0-562a63576a2c",
   "metadata": {},
   "outputs": [],
   "source": [
    "Records = LoadSeveralExperiments(N, T, m, OpinionAlphabet, AgentsArgs, BotsArgs, VariableParameters)\n",
    "\n",
    "ResultsWin = []\n",
    "\n",
    "for i in range(len(Records)):\n",
    "    \n",
    "    ResultsWin.append( [ (Records[i][1][-1] - Records[i][1][0]) ] )\n",
    "    \n",
    "distr2 = np.array(ResultsWin).ravel()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "165d07db-da82-4e92-b46d-ef1109545b5b",
   "metadata": {},
   "source": [
    "# Compare distributions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "5da04209-6434-45f0-8f00-60b3eeaa33f0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d2 < d1: 0.323\n",
      "\n",
      "d2 > d1: 0.682\n"
     ]
    }
   ],
   "source": [
    "stat, p = mannwhitneyu(distr2, distr1, alternative=\"less\")\n",
    "\n",
    "print('d2 < d1:', np.round(p, 3))\n",
    "\n",
    "print('')\n",
    "\n",
    "stat, p = mannwhitneyu(distr2, distr1, alternative=\"greater\")\n",
    "\n",
    "print('d2 > d1:', np.round(p, 3))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
